package com.example.googlemap;

import java.util.ArrayList;

import android.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;

import com.example.Dialog.DialogPanelDetail;
import com.example.object.ElectricPanels;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {

	private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();

	private Context context;
	int pos;
	ElectricPanels electricPanel;

	public CustomItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));

	}

	public CustomItemizedOverlay(Drawable defaultMarker, Context context,
			int pos) {
		this(defaultMarker);
		this.context = context;
		this.pos = pos;
	}

	public CustomItemizedOverlay(Drawable defaultMarker, Context context,
			ElectricPanels electricPanel) {
		this(defaultMarker);
		this.context = context;
		this.electricPanel = electricPanel;
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mapOverlays.get(i);
	}

	@Override
	public int size() {
		return mapOverlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		OverlayItem item = mapOverlays.get(index);
		if (pos != -1) {
			DialogPanelDetail myDialog = new DialogPanelDetail(context, pos);
			myDialog.show();
		}
		if (pos == -1) {
			DialogPanelDetail myDialog = new DialogPanelDetail(context,
					electricPanel);
			myDialog.show();
		}
		return true;
	}

	public void addOverlay(OverlayItem overlay) {
		mapOverlays.add(overlay);
		this.populate();
	}

}
